﻿using System;
using System.Drawing;
using System.Windows.Forms;
using AutoShuntingSchedule.UI.Forms;
using Sunny.UI;

namespace AutoShuntingSchedule.UI
{
    public partial class MainForm : UIHeaderMainFooterFrame
    {
        public static int ScheduleGraph = 1002;
        public static int PageStartIndex = 1000;

        public MainForm()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //uiTimePanel.Text = DateTime.Now.DateTimeString();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }

            //设置关联
            Header.TabControl = MainTabControl;

            //增加页面到Main
            AddPage(new RouteForm(), PageStartIndex);
            Header.CreateNode("交路维护", PageStartIndex);
            PageStartIndex++;

            AddPage(new SysDataForm(), PageStartIndex);
            Header.CreateNode("系统配置", PageStartIndex);
            PageStartIndex++;

            AddPage(new ScheduleGraphForm(), PageStartIndex);
            Header.CreateNode("调车图板", PageStartIndex);
            PageStartIndex++;

            AddPage(new FSymbols(), PageStartIndex);
            Header.CreateNode("字体图标", PageStartIndex);
            PageStartIndex++;

            AddPage(new FColorful(), PageStartIndex);
            Header.CreateNode("多彩主题", PageStartIndex);

            ////显示默认界面
            Header.SelectedIndex = 0;

            ////选中第一个节点
            //uiNavMenu1.SelectPage(1002);
            this.AutoScroll = true;
            this.uiScrollingText1.Text =
                $"中国铁道科学研究院集团有限公司（中国铁道科学研究院）始建于1950年，" +
                $"是我国铁路唯一的多学科、多专业的综合性研究机构。" +
                $"目前已发展成为集科技创新、技术服务、成果转化、工程实施等业务为一体的大型高科技企业集团。";

            //MainFormCommonLib.Instance.UIProgressIndicator = this.uiProgressIndicator1;
            //MainFormCommonLib.Instance.SetLocationToForm(ClientRectangle);
            //MainFormCommonLib.Instance.ActiveProgressIndicator(false);
        }

        private void Header_MenuItemClick(string itemText, int menuIndex, int pageIndex)
        {
            Footer.Text = "PageIndex: " + pageIndex;
        }

        private void MainForm_Shown(object sender, EventArgs e)
        {
            //var login = new FLogin();
            //login.ShowDialog(this);
            this.WindowState = FormWindowState.Maximized;
        }
    }

    public class MainFormCommonLib
    {
        public static MainFormCommonLib Instance = new Lazy<MainFormCommonLib>(() => new MainFormCommonLib()).Value;

        public Sunny.UI.UIProgressIndicator UIProgressIndicator { get; set; }

        public void ActiveProgressIndicator(bool flag)
        {
            //this.UIProgressIndicator.Active = flag;
            //this.UIProgressIndicator.Visible = flag;
            //if (flag)
            //{
            //    UIProgressIndicator.BringToFront();
            //    this.UIProgressIndicator.Start();
            //}
            //else
            //{
            //    this.UIProgressIndicator.Stop();
            //}
        }

        public void SetLocationToForm(int clientRectangleWidth, int clientRectangleHeight)
        {
            UIProgressIndicator.Location = new Point(clientRectangleWidth, clientRectangleHeight - UIProgressIndicator.Height);
        }

        public void SetLocationToForm(Rectangle rec)
        {
            //UIProgressIndicator.Location = new Point(rec.Width, rec.Height - UIProgressIndicator.Height);
        }
    }
}
